package com.mtao.mapper;

import com.mtao.entity.SysRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SysRoleMapper {
    /**
     * 查询所有角色
     * @return
     */
    @Select("select * from  sys_role")
    List<SysRole> findRoles();

    /**
     * 添加角色
     * @param sysRole
     */
    @Insert("insert into sys_role(role_code, role_name,create_time,description,update_time)" +
            "values (#{roleCode},#{roleName},#{createTime},#{description},#{updateTime})")
    void addRoles(SysRole sysRole);

    @Delete("delete from sys_role where id=#{id};")
    void delete(Integer id);

    @Select("select id,role_code,role_name,create_time,description,update_time from sys_role where id=#{roleId}")
    List<SysRole> getRoleByUserId(Integer roleId);

    @Select("select id,role_code,role_name,create_time,description,update_time from sys_role where role_name=#{roleName}")
    SysRole findName(String roleName);

    /**
     * 修改角色
     * @param sysRole
     */
    void updateRole(SysRole sysRole);

}
